import { createRouter, createWebHashHistory } from 'vue-router'
import HomeView from '../views/Homepage.vue'

const routes = [

  {
    path: '/',
    name: 'home',
    redirect: '/login',
    component: HomeView,
    children: [
      {
        path: '/basicinfor',//基本信息
        name: 'basicinfor',
        component: () => import('../views/BasicInfo.vue')
      },
      {
        path: '/economicdata',//经济数据
        name: 'economicdata',
        component: () => import('../views/EconomicData.vue')
      },
      {
        path: '/companyinfo',//企业信息
        name: 'companyinfo',
        component: () => import('../views/Companyinfo.vue')
      },
      {
        path: '/developmentmap',//开发区地图
        name: 'developmentmap',
        component: () => import('../views/Developmentmap.vue')
      },
      {
        path: '/inviteinvestment/Existingpro',//招商引资 已有
        name: 'Existingpro',
        component: () => import('../views/Existingpro.vue')
      },
      {
        path: '/inviteinvestment/Interms',//招商引资 在谈
        name: 'Interms',
        component: () => import('../views/Interms.vue')
      },

      {
        path: '/inviteinvestment/reserve',//招商引资 储备
        name: 'reserve',
        component: () => import('../views/reserve.vue')
      },
      {
        path: '/projectproposal',//项目建设
        name: 'projectproposal',
        component: () => import('../views/Projectproposal.vue')
      },
      {
        path: '/investmentpolicy',//招商政策
        name: 'investmentpolicy',
        component: () => import('../views/Investmentpolicy.vue')
      },
      {
        path: '/investmentpolicys',//招商政策更多
        name: 'investmentpolicys',
        component: () => import('../views/Investmentpolicys.vue')
      },
      {
        path: '/gsxq',//招商政策更多
        name: 'gsxq',
        component: () => import('../views/gsxq.vue')
      },
    ]
  },
  {
    path: '/login',//路由
    name: 'login',
    component: () => import('../views/Login.vue')
  },
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})
router.beforeEach((to, from, next) => {
  const token = sessionStorage.getItem("token")
  console.log(token, 123123);
  if(!token&&to.path!='/login'){
    next({path:'/login'})
  }else{
    next();
  }
})
export default router
